﻿
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging;
using HardToolApp.Model;
using HardToolApp.Tool;
using HardToolApp.View;
using OxyPlot;
using OxyPlot.Series;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace HardToolApp.ViewModel
{
    [ViewModelHelper("ADC",typeof(ADCPage),typeof(ADCModel),Sort=1)]
    internal class AdcVM: PeripheralVM
    {
        public RelayCommand fullData { get; }
        private void FullData()
        {
            new ADCFullPage((ADCModel)Model).Show();
        }

        
        public override void Rec(object t, byte[] b)
        {
            if (b[3] != (byte)CommCmd.COMM_ADC)
            {
                return;
            }
            switch(b[4])
            {
                case (byte)CommSubCmdADC.COMM_SUB_ADC_UPDATE:
                    ((ADCModel)Model).ch1.Add((ushort)((ushort)(b[5] * 256) + b[6]));
                    ((ADCModel)Model).ch2.Add((ushort)((ushort)(b[7] * 256) + b[8]));
                    ((ADCModel)Model).ch3.Add((ushort)((ushort)(b[9] * 256) + b[10]));
                    ((ADCModel)Model).ch4.Add((ushort)((ushort)(b[11] * 256) + b[12]));
                    ((ADCModel)Model).Plot.InvalidatePlot(true);
                    break;
            }
        }
        public AdcVM()
        {
            fullData = new RelayCommand(FullData);
        }
    }
}
